package com.future.lock.common.http.response;

import android.text.TextUtils;

import com.future.baselib.utils.JLog;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by jniu on 2017/11/27.
 */

public abstract class HttpResponse {

    public int success;
    public String msg;
    public String data;
    public int code;

    public void parse(String json){
        JLog.e("json", "json --- " + json);
        if (TextUtils.isEmpty(json)) {
            return;
        }
        try {
            JSONObject object = new JSONObject(json);
            success = object.optInt("success");
            msg = object.optString("msg");
            data = object.optString("data");
            code = object.optInt("code");
            parseData(data);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    protected abstract void parseData(String dataString) throws JSONException;
}
